package common.utils;

import com.fasterxml.jackson.databind.ObjectMapper;

public class JacksonUtil {

    private final static ObjectMapper objectMapper = new ObjectMapper();

    public static String serialize(Object value) {
        try {
            return objectMapper.writeValueAsString(value);
        } catch (Exception ex) {
            return ex.getMessage();
        }
    }

    public static <T> T deserialize(Class<T> tClass, String json) {
        try {
            return objectMapper.readValue(json, tClass);
        } catch (Exception ex) {
            LogUtil.warn(ex);
            return null;
        }
    }
}
